package leetcode.lt100;

import java.util.HashSet;
import java.util.Set;

class Solution_39 {
	public int lengthOfLongestSubstring(String s) {
		char[] ss = s.toCharArray();
		int l = ss.length;
		if (l == 0)
			return 0;
		int Max = 1;
		// 从每个起始点循环
		for (int i = 0; i < l && l - i > Max; i++) {
			Set<Character> set = new HashSet<Character>();
			// 记录当前起始点到结束点
			int end = i;
			while (end < l) {
				if (!set.add(ss[end])) {
					break;
				}
				end++;
			}
			Max = Math.max(Max, set.size());
		}
		return Max;
	}
}